package com.itheima.algorithm.sort;

import java.util.Arrays;

/*
冒泡排序
 */
public class BubbleSort {
    private static void bubble(int [] a){
        int j=a.length-1;
        while(true){
            int x=0;
            //每一轮排序
            for(int i=0;i<j;i++){
                if(a[i]>a[i+1]) {
                    int t = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = t;
                    //x记录最后无序的右边界
                    x = i;
                }
            }
            j=x;
            if(j==0){
                break;
            }
        }
    }

    public static void main(String[] args) {
        int[] a={6,5,4,3,2,1};
        System.out.println(Arrays.toString(a));
        bubble(a);
        System.out.println(Arrays.toString(a));
    }

}
